/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sirtet.netplay.server;

/**
 * An abstract factory for GameRoom objects
 * @author guangwei.zhu
 */
public abstract class GameRoomFactory {

    private final String typeString;

    public GameRoomFactory(String type) {
        this.typeString = type;
    }

    /**
     * Return a string indicating the type of the game which this factory supports.
     * @return a string of the game type name
     */
    public String getTypeString() {
        return this.typeString;
    }

    /**
     * Create a new raw GameRoom object, which will be post-processed and returned
     * by the <code>createRoom()</code> method.
     * @return a newly created GameRoom object
     */
    protected abstract GameRoom internalCreateRoom();

    /**
     * The external interface to obtain a newly created GameRoom object,  the
     * type string is enforced to be the same as that of this factory.
     * @return the newly created GameRoom object
     */
    public final GameRoom createRoom() {
        GameRoom room = this.internalCreateRoom();
        room.setGameType(this.typeString);

        return room;
    }
}
